import request from '../utils/request'

// 获取购物车列表
export function requestShoppingCart () {
    return new Promise(resolve => {
        request.post('/cart/list', {
            userid: localStorage.getItem('userid')
        }).then(res => {
            resolve(res.data)
        })
    })
}

// 添加购物车列表
export function requestAddCart (params = { userid: '', proid: '', num: '', size: undefined }) {
    return new Promise(resolve => {
        request.post('/cart/add', params).then(res => {
            resolve(res.data)
        })
    })
}

// 删除购物车单条数据
export function requestRemoveCart (params) {
    return new Promise(resolve => {
        request.post('/cart/remove', params).then(res => {
            resolve(res.data)
        })
    })
}

// 更新购物车数量
export function requestUpdateCart (params) {
    return new Promise(resolve => {
        request.post('/cart/updatenum', params).then(res => {
            resolve(res.data)
        })
    })
}

// 更新当前购物车列表项的选中状态
export function requestUpdateStateOne (cartid, bool) {
    return new Promise(resolve => {
        request.post('/cart/selectone', {
            cartid,
            flag: bool
        }).then(res => {
            resolve(res.data)
        })
    })
}

// 更新所有购物车列表选中状态
export function requestUpdateStateAll (bool = false) {
    return new Promise(resolve => {
        request.post('/cart/selectall', {
            userid: localStorage.getItem('userid'),
            flag: bool
        }).then(res => {
            resolve(res.data)
        })
    })
}
